import 'package:flutter_project/core/util/object_util.dart';

import 'constant.dart';
import 'manager/storage_manager.dart';

class Storage {
  static String _getKey(String key) {
    return Constant.KEY_PREFIX + key;
  }

  static void set(String key, String val) {
    var _key = _getKey(key);
    SharedPreferencesManager().putString(_key, val);
  }

  static String get(String key) {
    var _key = _getKey(key);
    return SharedPreferencesManager().getString(_key);
  }

  static void remove(String key) {
    var _key = _getKey(key);
    SharedPreferencesManager().remove(_key);
  }

  static void clear() {
    SharedPreferencesManager().clear();
  }

  static void setToken(String val) {
    var key = _getKey(Constant.KEY_TOKEN);
    set(key, val);
  }

  static String getToken() {
    var key = _getKey(Constant.KEY_TOKEN);
    return get(key);
  }

  static void setUser(String val) {
    var key = _getKey(Constant.KEY_USER);
    set(key, val);
  }

  static String getUser() {
    var key = _getKey(Constant.KEY_USER);
    return get(key);
  }

  static void setUserType(String val) {
    var key = _getKey(Constant.KEY_USER_TYPE);
    set(key, val);
  }

  static String getUserType() {
    var key = _getKey(Constant.KEY_USER_TYPE);
    return get(key);
  }

  static bool isGuest() {
    var token = getToken();
    return ObjectUtil.isEmptyString(token);
  }

  static void clearAuthData() {
    remove(Constant.KEY_TOKEN);
    remove(Constant.KEY_USER);
    remove(Constant.KEY_USER_TYPE);
  }
}
